package com.teradata.multithread.jdproviderconsumer;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * @Project: cmcchq
 * @Description:
 * @Version 1.0
 * @Throws :
 * @Author: <li>2019/6/14 lyndon Create 1.0
 * @Copyright (c)2019-2019 版权所有
 * @Modified By:
 */
public class Provider extends Thread {

    private ArrayBlockingQueue arrayBlockingQueue;

    public Provider(ArrayBlockingQueue arrayBlockingQueue) {
        this.arrayBlockingQueue = arrayBlockingQueue;
    }

    @Override
    public void run() {
        for (int i = 0; i <= 100; i++) {
            Apple apple = new Apple(i);
            try {
                arrayBlockingQueue.put(apple);
                System.out.println("Provider:" + apple.getNum());
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

}
